package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-09-17
 * Time: 9:40
 */
//懒汉模式，实现单例模式

    class SingletonLazy {
    private volatile static SingletonLazy instance = null;
        //所谓懒汉模式就是所说的先不创建实例
    public static SingletonLazy getInstance() {
        if (instance == null) {
            synchronized  (SingletonLazy.class){

            }
            if (instance == null) {
                instance = new SingletonLazy();
            }
        }


        return instance;
    }
    private SingletonLazy(){

    }
}
public class demo3 {
    public static void main(String[] args) {
        SingletonLazy  instance=SingletonLazy.getInstance();
    }
}
